package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;

import com.fgs.common.widget.itemView.DetailItemView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.DriverInfo;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2021/3/29
 * @description
 **/
public class DriverBindAdapter extends RecyclerArrayAdapter<DriverInfo> {
    private String driverId;

    public DriverBindAdapter(Context context) {
        super(context);
    }

    public void setDriverId(String driverId) {
        this.driverId = driverId;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new DriverBindViewHolder(parent, R.layout.item_driver_bind);
    }

    public class DriverBindViewHolder extends BaseViewHolder<DriverInfo> {

        private DetailItemView driverNameDetailItemView;
        private DetailItemView driverPhoneDetailItemView;
        private DetailItemView defaultVehicleDetailItemView;
        private DetailItemView bindStatusDetailItemView;

        public DriverBindViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            driverNameDetailItemView = getView(R.id.item_driver_bind_driverNameDetailItemView);
            driverPhoneDetailItemView = getView(R.id.item_driver_bind_driverPhoneDetailItemView);
            defaultVehicleDetailItemView = getView(R.id.item_driver_bind_defaultVehicleDetailItemView);
            bindStatusDetailItemView = getView(R.id.item_driver_bind_bindStatusDetailItemView);
            addOnClickListener(R.id.item_driver_bind_driverBindButton);
            addOnClickListener(R.id.item_driver_bind_driverUnbindButton);
            addOnClickListener(R.id.item_driver_bind_defaultDriverButton);
        }

        @Override
        public void setData(DriverInfo data) {
            super.setData(data);
            driverNameDetailItemView.setContent(data.drivername);
            driverPhoneDetailItemView.setContent(data.drivertel);
            defaultVehicleDetailItemView.setContent(data.defaultvehiclenum);
            if (!TextUtils.isEmpty(driverId)) {
                String[] ids = driverId.split(",");
                if (ids.length > 0) {
                    for (int i = 0; i < ids.length; i++) {
                        if (data.id.equals(ids[i])) {
                            bindStatusDetailItemView.setContent("已绑定");
                            bindStatusDetailItemView.setContentTextColor(getContext().getResources().getColor(R.color.colorGreen));
                            break;
                        } else {
                            bindStatusDetailItemView.setContent("未绑定");
                            bindStatusDetailItemView.setContentTextColor(getContext().getResources().getColor(R.color.colorTextPrimary));
                        }
                    }
                }
            }else {
                bindStatusDetailItemView.setContent("未绑定");
                bindStatusDetailItemView.setContentTextColor(getContext().getResources().getColor(R.color.colorTextPrimary));
            }
        }
    }
}
